home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / doc / python-gdata / examples / webmastertools / SitemapsFeedSummary.py < prev    next >
Encoding:
Python Source  |  2008-10-15  |  1.8 KB  |  69 lines

  1. #!/usr/bin/python
  2. #
  3. # Copyright (C) 2008 Yu-Jie Lin
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. #      http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16.  
  17.  
  18. import gdata.webmastertools.service
  19. import gdata.service
  20. try:
  21.   from xml.etree import ElementTree
  22. except ImportError:
  23.   from elementtree import ElementTree
  24. import atom
  25. import getpass
  26.  
  27.  
  28. username = ''
  29. password = ''
  30. site_uri = ''
  31.  
  32. username = raw_input('Please enter your username: ')
  33. password = getpass.getpass()
  34. site_uri = raw_input('Please enter your site url: ')
  35.  
  36. client = gdata.webmastertools.service.GWebmasterToolsService(
  37.     email=username, 
  38.     password=password, source='PythonWebmasterToolsSample-1')
  39.  
  40. print 'Logging in'
  41. client.ProgrammaticLogin()
  42.  
  43. print 'Retrieving Sitemaps feed'
  44. feed = client.GetSitemapsFeed(site_uri)
  45.  
  46. # Format the feed
  47. print
  48. print 'You have %d sitemap(s), last updated at %s' % (
  49.     len(feed.entry), feed.updated.text)
  50. print
  51. print '='*80
  52.  
  53.  
  54. def safeElementText(element):
  55.   if hasattr(element, 'text'):
  56.      return element.text
  57.   return ''
  58.  
  59.  
  60. # Format each site
  61. for entry in feed.entry:
  62.   print entry.title.text.replace('http://', '')[:80]
  63.   print "  Last Updated   : %29s              Status: %10s" % (
  64.       entry.updated.text[:29], entry.sitemap_status.text[:10])
  65.   print "  Last Downloaded: %29s           URL Count: %10s" % (
  66.       safeElementText(entry.sitemap_last_downloaded)[:29],
  67.       safeElementText(entry.sitemap_url_count)[:10])
  68. print
  69.